//do \\Make_ElecCounty_struct_demo_BLP_robustd_choiceset_2008_2012_v11_heter_inc_set_seed_bs_11022017.do



clear all
set more off
set mem 10000m
pause on



global pathname="/Volumes/RECHERCHE/FAC/HEC/DEEP/shoude/default/D2c/eegap/EEgap_data_code_heter_SM/Data_JPEmicro"
global censuspath=""
global sales_tax_path=""

local subsample=`"`1'"'                 //subsample: 44000
local group_id_selected=`"`2'"' 		//Income category to select: 1,2,3,4,5,6,16
local do_preprocess=`"`3'"' 
local do_price_ts=`"`4'"'
local set_seed=`"`5'"'
local dont_skip=`"`6'"'
set seed `set_seed' 



use "$pathname\electricity\county_elec_price_2007_2012", clear




use $pathname\refrigerators\kwh_046_2008_2012_v11022017_struct_`subsample'_`group_id_selected'_seed_`set_seed'_NoHd, clear
 	sort zipcode
	merge zipcode using $censuspath\mapping_zip_county_nov99
	tab _m
	drop if _m==2
	drop _m
	drop latitude longitude zip_class poname state county v8 v9
	ren county5 county_utility
 	sort county_utility year
	//merge county_utility year using "$pathname\electricity\county_price_tmp"  
  	merge county_utility year using "$pathname\electricity\county_elec_price_2007_2012"
	tab _m
  	drop if _m==2  
  	drop _m
  	//drop state
  	sort zipcode
  	merge zipcode using $pathname\refrigerators\map_zip_state_046_2008_2012_struct_tmp
  	tab _m
  	drop _m
  	sort state year
    merge state year using $pathname\electricity\electricity_price_state_2007_2012
    tab _m	
    tab state if _m==1
    drop if _m==2
  	replace pcount=p_elec if pcount==.
	sort state
	ren _m merge_eleccounty
	drop p_elec
	ren pcount p_elec
	replace p_elec=p_elec/100
	keep zipcode year tri week p_elec
    sort zipcode year tri week
save $pathname\refrigerators\elec_county_046_2008_2012_v11022017_struct_`subsample'_`group_id_selected'_seed_`set_seed'_NoHd, replace  
